package com.base.cn.platform.os.controller.netSchoolConfig.publicAccount;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.constants.ConfigName;
import com.base.cn.platform.os.entity.manage.config.SysConfig;
import com.base.cn.platform.os.service.manage.config.SysConfigService;
import com.base.cn.platform.os.service.manage.netSchoolConfig.publicAccount.PublicAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 后台分享海报Controller
 *
 * @since 2019/4/17
 */
@Controller
@RequestMapping("/admin/netSchoolConfig")
public class AdminPublicAccountController extends AdminBaseController {

    @Autowired
    private PublicAccountService publicAccountService;
    @Autowired
    private SysConfigService  sysConfigService;

    /**
     * 关注公众号
     *
     * @param model
     * @return
     */
    @RequestMapping("/accountConfig")
    public String queryAccountConfig(Model model){
        HashMap<String, Object> params = new HashMap<>();
        List<Map<String, Object>> maps = publicAccountService.queryPublicAccount(params);
        model.addAttribute("accountList",maps);
        SysConfig wxlogin = sysConfigService.getSysConfigByConfigType("WXLOGIN");
        model.addAttribute("wxlogin",wxlogin);
        SysConfig sysConfig = sysConfigService.getSysConfigByConfigType(ConfigName.WECHATSERVICE);
        model.addAttribute("sysConfig",sysConfig);

        return resultPage("/netSchoolConfig/publicAccount/account-config");
    }

    /**
     * 更新公众号配置
     *
     * @param
     * @return
     */
    @RequestMapping("/updateAccountConfig")
    @ResponseBody
    public Map<String,Object> updateAccountConfig (@RequestParam("id") Integer id,
                                                   @RequestParam("configStatus")Integer configStatus){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("configStatus",configStatus);
        return publicAccountService.updateAccountConfig(map);
    }

    /**
     * 保存公众号配置数据
     *
     * @param params
     * @return
     */
    @RequestMapping("/saveAccountConfig")
    @ResponseBody
    public Map<String, Object> saveAccountConfig(@RequestBody Map<String,Object> params) {
        return publicAccountService.saveAccountConfig(params);
    }

}
